//
//  MineViewModel.m
//  Futures
//
//  Created by Cheng on 2017/7/11.
//  Copyright © 2017年 Cheng. All rights reserved.
//

#import "MineViewModel.h"
#import "User.h"
#import "AccountInfo.h"

@implementation MineViewModel
// http://139.224.8.133:9100/api/login.ashx NSMutableDictionary * params = [NSMutableDictionary dictionary];params[@"uname"] = @"czx";params[@"upass"] = @"123456";
+ (void)requestLogin:(NSString *)account password:(NSString *)password block:(void (^)(User *user))block{
    NSDictionary *dict = @{@"uname":account,@"upass":password};
    [Network requestDataMethod:POST WithUrl:URL_LOGIN parameters:dict success:^(NSURLSessionDataTask *task, id responseObject) {
        NSDictionary *dict = responseObject;
        User *user = [[User alloc] initWithDict:dict];
        MYLog(@"%@",GLOBAL_INSTANCE.user.properties_aps);
        if (user.ReturnCode ==1) { // success!
            GLOBAL_INSTANCE.user = user;
        }
        block(user);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        MYLog(@"%@",error.description);
    }];
}

//18、获得资金状况
//传参：account
+ (void)requestAccountInfoWithBlock:(void (^)(id obj))block{
    NSDictionary *dict = @{@"account":GLOBAL_INSTANCE.user.cid};
    [Network requestDataMethod:GET WithUrl:URL_ACCOUNT_INFO parameters:dict success:^(NSURLSessionDataTask *task, id responseObject) {
        AccountInfo *model = [[AccountInfo alloc] initWithDict:responseObject];
        MYLog(@"%@",model.properties_aps);
        block(model);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}

@end
